<template>
  <cloudPage :isLoading="isLoading">
    <cloudHeader slot="gHeader">
      <view class="grace-header-body">
        <!-- 返回按钮 -->
        <view
          class="grace-header-icons grace-icons icon-arrow-left"
          style="color: #fff"
          @tap.stop="handleNavBack"
        ></view>
        <!-- 中间内容 -->
        <view
          class="grace-header-content-noflex grace-text-center"
          style="color: #fff; font-size: 36rpx"
        >
          {{ $t("mf.suanlibao.order_list") }}
        </view>
        <!-- 右侧按钮 -->
        <view class="icons grace-icons"></view>
      </view>
    </cloudHeader>
    <view class="container" v-if="!isLoading">
      <!-- <block v-for="(item, index) in suanliOrderList.data" :key="index">
        <suanli-order-box :suanli="item" @backSuanli="backSuanli" />
      </block> -->
      <block v-for="order in orderListSuanli.data" :key="order.id">
        <view class="box">
          <view class="flex top_list">
            <view class="flex1 suanli_name"
              >{{
                locale == "zh_TW"
                  ? order.goods_info.name
                  : order.goods_info.name_en
              }}
              {{ order.goods_info.days }}{{ $t("mf.suanlibao.day") }}</view
            >
            <button
              class="back_btn"
              @tap.stop="backSuanli(order.id, order.pay_num)"
              v-if="order.state != -1"
            >
              {{ $t("mf.suanlibao.back") }}
            </button>
            <view class="back" v-else>{{ $t("new.backed") }}</view>
          </view>
          <view class="flex">
            <view class="flex1">
              <view class="top_name">{{ $t("mf.suanlibao.amount") }}</view>
              <view class="bot_data"
                >{{ order.pay_num
                }}<text style="font-size: 28rpx">FIL</text></view
              >
            </view>
            <view class="flex1">
              <view class="top_name">{{
                $t("mf.suanlibao.total_profit")
              }}</view>
              <view class="bot_data">+{{ order.reward_release_num }}</view>
            </view>
            <view class="flex1">
              <view class="top_name">{{ $t("mf.suanlibao.end_day") }}</view>
              <view class="bot_data"
                >{{ order.days - order.release_days
                }}{{ $t("mf.suanlibao.day") }}</view
              >
            </view>
          </view>
        </view>
      </block>
      <graceLoading
        :loadingType="
          loading['mf.shop.suanlibao_order_list']
            ? 1
            : orderListSuanli.has_next_page
            ? 0
            : 2
        "
      ></graceLoading>
    </view>
    <graceBottomDialog
      :show="showBack"
      @closeDialog="closeShade"
      background="rgba(0,0,0,0.3)"
    >
      <view slot="content">
        <view class="shade_bottom_box">
          <view class="shade_title">{{ $t("mf.suanlibao.back") }}</view>
          <view class="explain"
            >{{ $t("mf.suanlibao.back_explain1")
            }}<text style="color: #ff6565">{{ number }}FIL</text
            >{{ $t("mf.suanlibao.back_explain2") }}</view
          >
          <view class="flex">
            <button class="cancel_btn" @tap.stop="closeShade">
              {{ $t("mf.suanlibao.cancel") }}
            </button>
            <button class="confirm_btn" @tap.stop="openPass">
              {{ $t("mf.suanlibao.confirm") }}
            </button>
          </view>
        </view>
      </view>
    </graceBottomDialog>
    <cloudPayPassword
      :show="showpay"
      @keyboardDone="payPasswordDone"
      @close="togglePayPassword"
    >
    </cloudPayPassword>
  </cloudPage>
</template>

<script>
// /pages/mf/shop/suanliOrderList
import { mapActions, mapGetters } from "vuex";
import suanliOrderBox from "./compontent/suanlibaoOrderBox";
export default {
  components: {
    suanliOrderBox,
  },
  data() {
    return {
      isLoading: false,
      showBack: false,
      backId: null,
      number: null,
      showpay: false,
      showSuccess: false,
      success_info: null,
    };
  },
  methods: {
    ...mapActions("mf/shop", ["loadOrderListSuanli", "redeemSuanlibao"]),
    backSuanli(id, num) {
      this.backId = id;
      this.number = num;
      this.showBack = true;
    },
    closeShade() {
      this.showBack = false;
    },
    closeShade2() {
      this.showSuccess = false;
    },
    togglePayPassword() {
      this.showpay = false;
    },
    openPass() {
      this.closeShade();
      this.showpay = true;
    },
    async payPasswordDone(data) {
      this.togglePayPassword();
      this.success_info = await this.redeemSuanlibao({
        order_id: this.backId,
        pay_password: data.password,
      });
      console.log(this.success_info);
      this.makeToast({ title: "赎回成功" });
      this.loadOrderListSuanli();
    },
  },
  computed: {
    ...mapGetters("system", ["locale"]),
    ...mapGetters("mf/shop", ["orderListSuanli"]),
  },
  async onLoad() {
    this.isLoading = true;
    await this.loadOrderListSuanli();
    console.log(this.orderListSuanli);
    this.isLoading = false;
  },
};
</script>

<style scoped>
.container {
  padding: 40rpx 20rpx 0;
}
.shade_bottom_box {
  width: 710rpx;
  height: 462rpx;
  background-color: #111;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  padding: 60rpx 30rpx 0;
  box-sizing: border-box;
}
.shade_title {
  height: 67rpx;
  font-size: 48rpx;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #ffffff;
  line-height: 67rpx;
  margin-bottom: 47rpx;
}
.explain {
  height: 50rpx;
  font-size: 36rpx;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.8);
  line-height: 50rpx;
  margin-bottom: 100rpx;
}
.back_btn {
  width: 310rpx;
  height: 88rpx;
  background: #646bff;
  /* box-shadow: 0px 4rpx 0px 0px #4B52E5; */
  border-radius: 10rpx;
  box-sizing: border-box;
  font-size: 30rpx;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
  line-height: 88rpx;
}
.cancel {
  box-shadow: none;
  background: rgba(0, 0, 0, 0);
  border-radius: 10rpx;
  border: 1px solid #ebebeb;
}
.shade_bottom_box2 {
  width: 710rpx;
  height: 846rpx;
  background-color: #111;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  padding: 60rpx 30rpx 0;
  box-sizing: border-box;
}
.shade_bottom_box2 image {
  width: 192rpx;
  height: 192rpx;
  border-radius: 50%;
  margin-bottom: 50rpx;
}
.success_title {
  height: 50rpx;
  font-size: 36rpx;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #ffffff;
  line-height: 50rpx;
  margin-bottom: 20rpx;
}
.box {
  width: 100%;
  height: 270rpx;
  background: linear-gradient(270deg, #1b1b2b 0%, #232534 100%);
  box-shadow: 0px 3px 4px 0px rgba(0, 0, 0, 0.5);
  border-radius: 12px;
  margin-bottom: 30rpx;
  padding: 32rpx 40rpx;
  box-sizing: border-box;
}
.suanli_name {
  height: 28rpx;
  font-size: 28rpx;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #ffffff;
  line-height: 28rpx;
}
.top_list {
  align-items: center;
  margin-bottom: 50rpx;
}
.back_btn {
  width: 100rpx;
  height: 48rpx;
  background: linear-gradient(150deg, #fee8b2 0%, #ffdb82 100%);
  border-radius: 10rpx;
  line-height: 48rpx;
  font-size: 30rpx;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #1f1f2c;
  box-sizing: border-box;
  padding: 0;
}
.top_name {
  height: 40rpx;
  font-size: 24rpx;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.6);
  line-height: 40rpx;
  margin-bottom: 20rpx;
  text-align: center;
}
.bot_data {
  height: 59rpx;
  font-size: 28rpx;
  font-family: PingFangSC-Semibold, PingFang SC;
  font-weight: 600;
  color: #ffdb82;
  line-height: 59rpx;
  text-align: center;
}
.back {
  font-size: 28rpx;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffdb82;
}
.cancel_btn {
  width: 300rpx;
  height: 80rpx;
  background: rgba(0, 0, 0, 0);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-sizing: border-box;
  color: rgba(255, 255, 255, 0.4);
  line-height: 80rpx;
}
.confirm_btn {
  width: 300rpx;
  height: 80rpx;
  background: linear-gradient(150deg, #fee8b2 0%, #ffdb82 100%);
  box-sizing: border-box;
  color: #1f1f2c;
  line-height: 80rpx;
}
</style>